package com.pkk.penguin.uti.oss.config;

import com.pkk.components.encryption.factory.JasyptEncryFactory;
import com.pkk.components.encryption.factory.JasyptEncryFactoryInterface;
import com.pkk.components.util.YmlParserUtil;
import java.io.InputStream;
import java.util.Map;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;

/**
 * @description: oss的配置加载
 * @author: peikunkun
 * @create: 2018-09-16 15:42
 **/
@Slf4j
public class OssConfig {


  /**
   *加载配置文件
   */
  static {
    Map<String, String> map = null;
    final String config = "/config/ossconfig.yml";
    final InputStream in = OssConfig.class.getClass().getResourceAsStream(config);
    map = YmlParserUtil.parserYmlToProperties(in);

    //获取服务器密钥
    final String encryptorPwd = System.getProperty("jasypt.encryptor.password");
    Optional.ofNullable(encryptorPwd)
        .orElseThrow(() -> new IllegalArgumentException("param [jasypt.encryptor.password] Con not be blank!"));

    //解密操作
    JasyptEncryFactoryInterface jasyptEncryFactoryInterface = new JasyptEncryFactory();
    jasyptEncryFactoryInterface.getInstance(encryptorPwd);

    SECRETID = jasyptEncryFactoryInterface.decode(map.get("baseoss.config.tencent.secretId"));
    SECRETKEY = jasyptEncryFactoryInterface.decode(map.get("baseoss.config.tencent.secretKey"));
    REGIONNAME = jasyptEncryFactoryInterface.decode(map.get("baseoss.config.tencent.regionName"));
    BUCKETNAME = jasyptEncryFactoryInterface.decode(map.get("baseoss.config.tencent.bucketName"));
  }

  /**
   * 密钥id
   */
  public static String SECRETID;
  /**
   * 密钥id
   */
  public static String SECRETKEY;
  /**
   * 地域简介
   */
  public static String REGIONNAME;
  /**
   * 存储桶名称
   */
  public static String BUCKETNAME;

}
